import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
// import config from '~/webpack.config.babel';
import webpack from 'webpack';

import path from 'path';


const config = {
    devtool: 'eval',
    entry: [
        'webpack-hot-middleware/client',
        './src/app.js'
        ],
    plugins: [
      new webpack.HotModuleReplacementPlugin(),
      new webpack.NoErrorsPlugin(),
    ],
    output: {
        path: path.join(__dirname, '/dist'),
        filename: 'bundle.js',
        publicPath: '/'
    },
    module: {
      loaders: [{
        test: /\.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['react-hmre'],
        },
      }],
    }
}

const bundler = webpack(config);

const middleware = [
  webpackDevMiddleware(bundler, {
    filename: 'app.js',
    publicPath: '/',
    hot: true,
    stats: {
      colors: true,
    },
  }),
  webpackHotMiddleware(bundler, {
    log: console.log, // eslint-disable-line no-console
  }),
  // historyFallback(),
];

export { middleware as hotMiddleware}